Ext.ns('Wlanauth.operator');
/**
 * 操作员管理
 */
Wlanauth.operator.GridPanel = Ext.extend(Wlanauth.BaseGridPanel,{
	title:'操作员管理',
	storeUrl:'operator!list.action',
	constructor:function(config){
	
		Ext.apply(this,config);
		
		this.store = new Ext.data.JsonStore({
			url:this.storeUrl,
			totalProperty:'data',
			root:'rows',
			fields:['id','username','displayname','email','role',
			        'sexId','address','status','description',
			        {name:'birth',type:'date',dateFormat:'Y-m-d h:i:s'}]
			
		});
		var sm = new Ext.grid.CheckboxSelectionModel({singleSelect:false});
		Wlanauth.operator.GridPanel.superclass.constructor.call(this,{
			loadMask:true,
			sm:sm,
			cm:new Ext.grid.ColumnModel({
				columns:[new Ext.grid.RowNumberer(),sm,
					{header:'用户名',dataIndex:'username',width:120},
					{header:'姓名',dataIndex:'displayname',width:120},
				    {header:'角色',dataIndex:'role',width:120,sortable:true,renderer:this.roleRender},
				    {header:'电话',dataIndex:'contactPhone',width:130,sortable:true},
				    {header:'邮箱',dataIndex:'email',width:150,sortable:true},
				    {header:'地址',dataIndex:'address',width:150},
				    {header:'备注',id:'description',dataIndex:'description'}
				   
			    ]}),
		     viewConfig: {
	            forceFit: true
			 },
			 autoExpandColumn:'desc',
			 tbar:[{
				 text:'添加',
				 iconCls:'add',
				 handler:this.addObject,
				 hidden:!ZZExt.ApplicationContext.actionAccessable('wlanauth.operator.add')
			 },'-',{
				 text:'修改',
				 iconCls:'edit',
				 handler:this.editObject,
				 scope:this,
				
			 },'-',{
				 text:'删除',
				 iconCls:'delete',
				 handler:this.deleteObject,
				 scope:this,
				 hidden:!ZZExt.ApplicationContext.actionAccessable('wlanauth.operator.delete')
			 }]
		});
		
		this.addSimpleSearchBar([['用户名','entity.username'],['姓名','entity.displayname'],['邮箱','entity.email']]);
		this.fireEvent('autoload');
		this.on('rowdblclick',this.editObject,this);
	},
	roleRender:function(role,meta,record,row,col,store){
		if(role!=null) return role.name+'['+role.code+']';
	},
	addObject:function(){
		ZZExt.ApplicationContext.openTab('wlanauth.operator.formpanel');
	},
	editObject:function(){
		var r = this.getSelectionModel().getSelected();
		if(!r){Ext.Msg.alert('提示','请选择一项');return;}
		var editable = ZZExt.ApplicationContext.actionAccessable('wlanauth.operator.edit');
		var user = ZZExt.ApplicationContext.getUser();
		if(r.get('id')!=user.id){
			if(!editable){
				Ext.Msg.alert('警告','<font style="color:red">您无权修改其它操作员信息!</font>');
				return ;
			} else {
				if(r.get('role').level>user.role.level){
					Ext.Msg.alert('警告','<font style="color:red">您无权修改该操作员信息!</font>');
					return ;
				} 
			}
		}
		ZZExt.ApplicationContext.openTab('wlanauth.operator.formpanel',{editMode:'UPDATE',ZZExtParams:{id:r.get('id')}});
	},
	deleteObject:function(){
		var grid = this;
		var r = this.getSelectionModel().getSelected();
		if(!r){Ext.Msg.alert('提示','请选择一项');return;}
		Ext.Msg.confirm('警告','您确定删除该条记录吗?<br/>',function(btn){
			if(btn=='yes'){
				Ext.Msg.wait('删除...');
				Ext.Ajax.request({
					url:'operator!delete.action?entity.id='+r.get('id'),
					success:function(response,opts){
						if(checkException(response)){
							grid.getStore().reload();
							Ext.Msg.alert('提示','删除成功');
							
						}
					}
				
				});
			} 
		});
		
	}
	
});

Ext.reg('wlanauth.operator.gridpanel',Wlanauth.operator.GridPanel);